<template>
	<div>
		<vxe-modal v-model="dialogVisible" title="用户权限管理" width="1000" height="730" show-zoom resize remember>
			<template #default>
				<vxe-toolbar :refresh="{query: reload}">
					<template #buttons>
						<vxe-button status="success" size="mini" @click="allcheck">全选</vxe-button>
						<vxe-button status="primary" size="mini" @click="getUpdateEvent">保存修改</vxe-button>
					</template>
				</vxe-toolbar>
				<vxe-table :height="600" resizable show-overflow keep-source ref="xTable" :print-config="{}"
					:export-config="{}" :loading="loading"
					:tree-config="{transform: true, expandAll: true, trigger: 'row', rowField: 'id', parentField: 'parentId'}"
					:edit-config="{trigger: 'click', mode: 'row', showStatus: true}"
					:checkbox-config="{checkField: 'select',checkStrictly:true}" :data="tableData" size="mini">
					<vxe-column type="checkbox" width="60"></vxe-column>
					<vxe-column field="name" tree-node title="名称">
					</vxe-column>
				</vxe-table>
			</template>

		</vxe-modal>
	</div>
</template>

<script>
	import XEUtils from 'xe-utils'
	import datajson from '@/views/util/data.json'
	import {
		list,
		Authority,
		addAuthority
	} from './index.js'
	export default {
		components: {

		},
		data() {
			return {
				loading: false,
				dialogVisible: false,
				userinfo: {},
				parm : {
					"menuIdList": [],
					"userId": 0
				},
				comid: '',
				tableData: [],
				companylist: []
			}
		},
		created() {
			let userinfo = JSON.parse(localStorage.getItem("userinfo"));
			this.userinfo = userinfo;
			this.comid = userinfo.companyid;
			this.oldlist();
		},
		methods: {
			open(e) {
				console.log(e);
				this.Authority(e);
				this.parm.userId = e.id;
				this.dialogVisible = true;
			},
			reload() {
				const $table = this.$refs.xTable
				// 清除所有状态
				$table.clearAll()
				return this.findList()
			},
			allcheck(){
				//console.log("全选");
				this.$refs.xTable.setAllCheckboxRow(true);
				this.tableData.forEach(item=>{
					item.select = true;
				})
				this.$forceUpdate();
			},
			//保存
			getUpdateEvent() {
				const $table = this.$refs.xTable
				const selectRecords = $table.getCheckboxRecords();
				console.log(selectRecords);
				let plist = [];
				selectRecords.forEach(item=>{
					plist.push(item.id);
				})
				this.parm.menuIdList = plist;
				this.sava();
			},
			async Authority(parm) {
				let result = await Authority(parm);
				//console.log("返回结果", result);
				this.tableData = result.obj;
			},
			async oldlist() {
				// this.loading = true;
				// let parm = {}
				// let result = await list(parm);
				//console.log("返回结果", result);
				this.loading = false;
				// this.tableData = result.obj;
				this.tableData = datajson.rolelist;
			},

			async sava() {
				let result = await addAuthority(this.parm);
				if (result.code == 1) {
					this.msgSuccess("保存成功");
				}
			}

		}
	};
</script>

<style></style>
